package com.que.owen.controller;

import com.que.owen.entity.User;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName TestController
 * @Author Owen.Que
 * @Description
 * @Date 8/29/2018 11:27
 **/
@RestController
@RequestMapping(value = "/test")
@Validated
public class TestController {

    @GetMapping(value = "/method1/{param1}")
    @ApiOperation(value = "test method1", notes = "firstTest")
    public ResponseEntity firstTest(@PathVariable(value = "param1") String param1,@NotBlank String p2){
        System.out.println(String.format("get parameters, param1=%s;param2=%s",param1,p2));
        Map map=new HashMap();
        map.put("param1",param1);
        map.put("p2",p2);
        return ResponseEntity.ok(map);
    }

    @PostMapping(path = "/method2/{param1}")
    @ApiOperation(value = "test method1", notes = "firstTest")
    public ResponseEntity secondTest(@Valid @RequestBody User user){
        System.out.println(user.toString());
        return ResponseEntity.ok(user.getName());
    }
}
